#!/bin/bash
#
# Copyright © 2016-2020 The Thingsboard Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

set -e

source .env
export DOCKER_REPO=${DOCKER_REPO}
export TB_VERSION=${TB_VERSION}
export TE_SITE_CODE=${TE_SITE_CODE}
export REDIS_NODES=${REDIS_NODES}
export REDIS_PASSWORD=${REDIS_PASSWORD}
export ZOOKEEPER_URL=${ZOOKEEPER_URL}
export TB_KAFKA_SERVERS=${TB_KAFKA_SERVERS}


export TE_EXPORT_ENABLE=${TE_EXPORT_ENABLE}
export TE_EXPORT_TYPE=kafka
export TE_EXPORT_KAFKA_SERVERS=${TE_EXPORT_KAFKA_SERVERS}
export TE_RECEIVER_KAFKA_SERVERS=${TE_EXPORT_KAFKA_SERVERS}
export DATA_RETAIN_TIME=${DATA_RETAIN_TIME}
export DATA_EXPIRE_LINE=${DATA_EXPIRE_LINE}

kubectl config set-context $(kubectl config current-context) --namespace=intelligence-plat

kubectl apply -f tb-node-configmap.yml
kubectl apply -f tb-transport-configmap.yml
envsubst < thingsboard.yml | kubectl apply -f -
envsubst < tb-node.yml | kubectl apply -f -
envsubst < tb-core.yml | kubectl apply -f -

# kubectl apply -f routes.yml

